import cv2
import os

def process(line):
    if not line:
        return

    list = line.split(" ")
    #print("list: ", list)
    filepath = list[0].strip()
    print("ssssssssssssss"+filepath+"ssssssssssssssssssssssssssss")

    im = cv2.imread(filepath) #AFW_1051618982_1_0.jpg")

    #w = 112
    h, w = im.shape[0:2]
    #print("h, w: ", h, w)
    H = h * 8
    W = w * 8
    
    imr = cv2.resize(im, (H, W)) 

    deslist = []
    #desstr = ""
    x = -9999
    y = -9999
    idx = 0
    for i in range(len(list)):
        if i == 0:
            deslist.append(list[i])
        else:
            num = float(list[i])

            if num == -256.0:
                continue

            if x == -9999:
                num = int(num * W)
                #print("22222: ", num)
                x = num
                numstr = str(num)
                #print("3333: ", numstr)
                deslist.append(numstr)
            elif y == -9999:
                num = int(num * H)
                #print("22222: ", num)
                y = num
                numstr = str(num)
                #print("3333: ", numstr)
                deslist.append(numstr)

        if x!=-9999 and y!=-9999:
            cv2.circle(imr, (x, y), 2, (0,0,255), 1)
            cv2.putText(imr, str(idx), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0,255,0), 1)
            x = -9999
            y = -9999
            idx += 1

    #print(deslist)
    #for i in range(len(deslist)):
    #    desstr = desstr + " " + deslist[i]
    #print(desstr)

    tmplist = filepath.split("/")
    filen = tmplist[-1]
    cv2.imwrite("./tmp/" + filen, imr)


if __name__ == "__main__":
    """
    PFPLD labeled info check
    lhf
    2022.4.18
    """

    fold = "./tmp"
    isExists = os.path.exists(fold)
    if not isExists:
        os.makedirs(fold)

    with open("list.txt", "r") as f:
        line = f.readline()
        process(line)
        while line:
            line = f.readline()
            process(line)
    f.close()


    #str0 = "imgs/WIN_20220330_14_34_55_Pro.jpg 0.007537688442211055 0.21105527638190955 -256.0 -256.0 0.010050251256281407 0.3768844221105528 -256.0 -256.0 0.02763819095477387 0.5452261306532663 -256.0 -256.0 0.05778894472361809 0.6532663316582915 -256.0 -256.0 0.10804020100502512 0.7537688442211056 -256.0 -256.0 0.18090452261306533 0.8417085427135679 -256.0 -256.0 0.2663316582914573 0.9170854271356784 -256.0 -256.0 0.36683417085427134 0.9773869346733668 -256.0 -256.0 0.49246231155778897 1.0 -256.0 -256.0 0.6206030150753769 0.9798994974874372 -256.0 -256.0 0.7286432160804021 0.9221105527638191 -256.0 -256.0 0.8241206030150754 0.8492462311557789 -256.0 -256.0 0.9020100502512562 0.7613065326633166 -256.0 -256.0 0.9522613065326633 0.6582914572864321 -256.0 -256.0 0.9798994974874372 0.542713567839196 -256.0 -256.0 0.9974874371859297 0.37185929648241206 -256.0 -256.0 1.0075376884422111 0.20351758793969849 0.11306532663316583 0.08793969849246232 0.17839195979899497 0.04522613065326633 0.25879396984924624 0.02512562814070352 0.3442211055276382 0.02763819095477387 0.41959798994974873 0.052763819095477386 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 0.5703517587939698 0.06532663316582915 0.6507537688442211 0.05025125628140704 0.7361809045226131 0.04773869346733668 0.8190954773869347 0.06030150753768844 0.8894472361809045 0.09547738693467336 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 -256.0 0.48743718592964824 0.1934673366834171 0.48743718592964824 0.2663316582914573 0.49246231155778897 0.36683417085427134 0.4949748743718593 0.44221105527638194 0.37185929648241206 0.47738693467336685 0.4045226130653266 0.5 0.4824120603015075 0.5276381909547738 0.5653266331658291 0.5025125628140703 0.5954773869346733 0.4798994974874372 0.17587939698492464 0.19597989949748743 0.23869346733668342 0.1658291457286432 -256.0 -256.0 0.28391959798994976 0.16331658291457288 0.3492462311557789 0.18592964824120603 0.28391959798994976 0.19597989949748743 -256.0 -256.0 0.24120603015075376 0.1984924623115578 0.6381909547738693 0.1934673366834171 0.7060301507537688 0.17839195979899497 -256.0 -256.0 0.7537688442211056 0.17839195979899497 0.8165829145728644 0.1984924623115578 0.7512562814070352 0.20100502512562815 -256.0 -256.0 0.7085427135678392 0.1984924623115578 0.2914572864321608 0.6884422110552764 0.35678391959798994 0.6457286432160804 0.43467336683417085 0.628140703517588 0.4798994974874372 0.6381909547738693 0.5251256281407035 0.628140703517588 0.5954773869346733 0.6507537688442211 0.6482412060301508 0.6959798994974874 0.6080402010050251 0.7361809045226131 0.5527638190954773 0.7638190954773869 0.4798994974874372 0.7713567839195979 0.4020100502512563 0.7587939698492462 0.3417085427135678 0.7311557788944724 0.3492462311557789 0.6884422110552764 0.3869346733668342 0.6733668341708543 0.4798994974874372 0.6809045226130653 0.5628140703517588 0.678391959798995 0.6005025125628141 0.6934673366834171 0.5653266331658291 0.7010050251256281 0.4798994974874372 0.7060301507537688 0.3869346733668342 0.6959798994974874 -256.0 -256.0 -256.0 -256.0 0 0 0 0 0 0 5.631132 3.518512 1.8095624 0"
